from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep


#调用驱动，打开Chrome浏览器
driver = webdriver.Chrome()
sleep(2)
#输入网址,打开百度新闻网站
driver.get('https://news.baidu.com')
sleep(2)
#单击热点新闻第二条
secondnews = driver.find_element(By.CSS_SELECTOR, "#pane-news > div > ul > li.hdline1 > strong > a:nth-child(1)").click()
sleep(2)
current = driver.current_window_handle
all_handles = driver.window_handles
print(current)
driver.switch_to.window(all_handles[1])
print(driver.current_window_handle)
print(driver.title)
sleep(2)
driver.close()
driver.switch_to.window(all_handles[0])
sleep(2)
driver.find_element(By.CSS_SELECTOR,"#ww").send_keys("新闻标题")
sleep(2)
driver.find_element(By.CSS_SELECTOR,"#s_btn_wr").click()
sleep(2)
driver.quit()
